package top.zhangjianyong.blog.manage.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.params.category.CategoryRemoveParam;
import top.zhangjianyong.blog.params.category.CategorySaveOrUpdateParam;
import top.zhangjianyong.blog.params.category.CategoryTreeParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.CategoryService;

/**
 * 分类
 *
 * @author zhangjianyong
 * @since 2024/7/31 上午10:30
 */
@RequestMapping("/category")
@RestController
public class CategoryController {

  private final CategoryService categoryService;

  public CategoryController(CategoryService categoryService) {
    this.categoryService = categoryService;
  }

  @PostMapping("/tree")
  public ApiResponse tree(@RequestBody @Validated CategoryTreeParam param) {
    return categoryService.tree(param);
  }

  @PostMapping("/saveOrUpdate")
  public ApiResponse saveOrUpdate(@RequestBody @Validated CategorySaveOrUpdateParam param) {
    return categoryService.saveOrUpdate(param);
  }

  @PostMapping("/remove")
  public ApiResponse remove(@RequestBody @Validated CategoryRemoveParam param) {
    return categoryService.remove(param);
  }
}
